Test Setup Failed
Push — master ( 51607c...6b8ca8 )
by Paul
03:43
created

GLSR.onChangeStatus   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 7
rs 9.4285
1
GLSR.colorControls = function()
0 ignored issues
show
Bug introduced by
The variable GLSR seems to be never declared. If this is a global, consider adding a /** global: GLSR */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
2
{
3
	if( typeof x.wp !== 'object' || typeof x.wp.wpColorPicker !== 'function' )return;
0 ignored issues
show
Bug introduced by
The variable x seems to be never declared. If this is a global, consider adding a /** global: x */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
4
5
	x( document ).find( 'input[type="text"].color-picker-hex' ).each( function() {
6
		var t = x( this );
7
		var options = t.data( 'colorpicker' ) || {};
8
		t.wpColorPicker( options );
9
	});
10
};
11
12
GLSR.dismissNotices = function()
0 ignored issues
show
Bug introduced by
The variable GLSR seems to be never declared. If this is a global, consider adding a /** global: GLSR */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
13
{
14
	x( '.notice.is-dismissible' ).each( function() {
15
		var notice = x( this );
16
		notice.fadeTo( 100, 0, function() {
17
			notice.slideUp( 100, function() {
18
				notice.remove();
19
			});
20
		});
21
	});
22
};
23
24
GLSR.getURLParameter = function( name )
0 ignored issues
show
Bug introduced by
The variable GLSR seems to be never declared. If this is a global, consider adding a /** global: GLSR */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
25
{
26
	return decodeURIComponent(
27
		(new RegExp( '[?|&]' + name + '=' + '([^&;]+?)(&|#|;|$)' ).exec( location.search ) || [null, ''])[1].replace( /\+/g, '%20' )
28
	) || null;
29
};
30
31
GLSR.insertNotices = function( notices )
0 ignored issues
show
Bug introduced by
The variable GLSR seems to be never declared. If this is a global, consider adding a /** global: GLSR */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
32
{
33
	notices = notices || false;
34
35
	if( !notices )return;
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
36
37
	if( !x( '#glsr-notices' ).length ) {
38
		x( '#message.notice' ).remove();
39
		x( 'form#post' ).before( '<div id="glsr-notices" />' );
40
	}
41
42
	x( '#glsr-notices' ).html( notices );
43
44
	x( document ).trigger( 'wp-updates-notice-added' );
45
};
46
47
GLSR.isUndefined = function( value )
0 ignored issues
show
Bug introduced by
The variable GLSR seems to be never declared. If this is a global, consider adding a /** global: GLSR */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
48
{
49
	var is_undefined = void(0);
0 ignored issues
show
Coding Style introduced by
Consider using undefined instead of void(0). It is equivalent and more straightforward to read.
Loading history...
50
	return value === is_undefined;
51
};
52
53
GLSR.normalizeValue = function( value )
0 ignored issues
show
Bug introduced by
The variable GLSR seems to be never declared. If this is a global, consider adding a /** global: GLSR */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
54
{
55
	if(['true','on','1'].indexOf( value ) > -1 ) {
56
		return true;
57
	}
58
59
	if(['false','off','0'].indexOf( value ) > -1 ) {
60
		return false;
61
	}
62
63
	return value;
64
};
65
66
GLSR.normalizeValues = function( array )
0 ignored issues
show
Bug introduced by
The variable GLSR seems to be never declared. If this is a global, consider adding a /** global: GLSR */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
67
{
68
	return array.map( GLSR.normalizeValue );
0 ignored issues
show
Bug introduced by
The variable GLSR seems to be never declared. If this is a global, consider adding a /** global: GLSR */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
69
};
70
71
GLSR.onChangeStatus = function( ev )
72
{
73
	var post_id = this.href.match(/post=([0-9]+)/)[1];
74
	var status  = this.href.match(/action=([a-z]+)/)[1];
75
76
	if( GLSR.isUndefined( status ) || GLSR.isUndefined( post_id ))return;
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
Bug introduced by
The variable GLSR seems to be never declared. If this is a global, consider adding a /** global: GLSR */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
77
78
	var request = {
79
		action: 'change-review-status',
80
		status : status,
81
		post_id: post_id,
82
	};
83
84
	GLSR.postAjax( ev, request, function( response )
85
	{
86
		var el = x( ev.target );
87
88
		el.closest( 'tr' ).removeClass( 'status-pending status-publish' ).addClass( response.class );
89
		el.closest( 'td.column-title' ).find( 'strong' ).html( response.link );
90
	});
91
};
92
93
GLSR.onClearLog = function( ev )
0 ignored issues
show
Bug introduced by
The variable GLSR seems to be never declared. If this is a global, consider adding a /** global: GLSR */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
94
{
95
	var request = {
96
		action: 'clear-log',
97
	};
98
	GLSR.postAjax( ev, request, function( response )
0 ignored issues
show
Bug introduced by
The variable GLSR seems to be never declared. If this is a global, consider adding a /** global: GLSR */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
99
	{
100
		GLSR.insertNotices( response.notices );
0 ignored issues
show
Bug introduced by
The variable GLSR seems to be never declared. If this is a global, consider adding a /** global: GLSR */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
101
		x( '#log-file' ).val( response.logger );
102
	});
103
};
104
105
GLSR.onFieldChange = function()
106
{
107
	var depends = x( this ).closest( 'form' ).find( '[data-depends]' );
108
109
	if( !depends.length )return;
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
110
111
	var name  = this.getAttribute( 'name' );
112
	var type  = this.getAttribute( 'type' );
113
114
	for( var i = 0; i < depends.length; i++ ) {
115
116
		try {
117
			var data = JSON.parse( depends[i].getAttribute( 'data-depends' ) );
118
			var bool;
119
120
			if( data.name !== name )continue;
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
121
122
			if( 'checkbox' === type ) {
123
				bool = !!this.checked;
124
			}
125
			else if( x.isArray( data.value ) ) {
0 ignored issues
show
Bug introduced by
The variable x seems to be never declared. If this is a global, consider adding a /** global: x */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
126
				bool = x.inArray( GLSR.normalizeValue( this.value ), GLSR.normalizeValues( data.value ) ) !== -1;
0 ignored issues
show
Bug introduced by
The variable GLSR seems to be never declared. If this is a global, consider adding a /** global: GLSR */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
127
			}
128
			else {
129
				bool = GLSR.normalizeValue( data.value ) === GLSR.normalizeValue( this.value );
130
			}
131
132
			GLSR.toggleHiddenField( depends[i], bool );
133
		}
134
		catch( e ) {
135
			console.error( 'JSON Error: ' + depends[i] );
136
		}
137
	}
138
};
139
140
GLSR.pointers = function( pointer )
141
{
142
	x( pointer.target ).pointer({
143
		content: pointer.options.content,
144
		position: pointer.options.position,
145
		close: function() {
146
			x.post( ajaxurl, {
0 ignored issues
show
Bug introduced by
The variable ajaxurl seems to be never declared. If this is a global, consider adding a /** global: ajaxurl */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
Bug introduced by
The variable x seems to be never declared. If this is a global, consider adding a /** global: x */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
147
				pointer: pointer.id,
148
				action: 'dismiss-wp-pointer',
149
			});
150
		},
151
	})
152
	.pointer( 'open' )
153
	.pointer( 'sendToTop' );
154
155
	x( document ).on( 'wp-window-resized', function() {
156
		x( pointer.target ).pointer( 'reposition' );
157
	});
158
};
159
160
GLSR.postAjax = function( ev, request, callback )
0 ignored issues
show
Bug introduced by
The variable GLSR seems to be never declared. If this is a global, consider adding a /** global: GLSR */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
161
{
162
	ev.preventDefault();
163
	var el = x( ev.target );
164
	if( el.is( ':disabled' ))return;
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
165
	request.nonce = request.nonce || el.closest( 'form' ).find( '#_wpnonce' ).val();
166
	var data = {
167
		action: site_reviews.action,
0 ignored issues
show
Bug introduced by
The variable site_reviews seems to be never declared. If this is a global, consider adding a /** global: site_reviews */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
168
		request: request,
169
	};
170
	el.prop( 'disabled', true );
171
	x.post( site_reviews.ajaxurl, data, function( response ) {
0 ignored issues
show
Bug introduced by
The variable x seems to be never declared. If this is a global, consider adding a /** global: x */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
172
		if( typeof callback === 'function' ) {
173
			callback( response );
174
		}
175
		el.prop( 'disabled', false );
176
	});
177
};
178
179
GLSR.textareaResize = function( el )
0 ignored issues
show
Bug introduced by
The variable GLSR seems to be never declared. If this is a global, consider adding a /** global: GLSR */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
180
{
181
	var minHeight = 320;
182
	var textarea  = el[0];
183
184
	textarea.style.height = 'auto';
185
186
	textarea.style.height = textarea.scrollHeight > minHeight ?
187
		textarea.scrollHeight + 'px' :
188
		minHeight + 'px';
189
};
190
191
GLSR.toggleHiddenField = function( el, bool )
0 ignored issues
show
Bug introduced by
The variable GLSR seems to be never declared. If this is a global, consider adding a /** global: GLSR */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
192
{
193
	var row = x( el ).closest( '.glsr-field' );
194
195
	if( !row.length )return;
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
196
197
	if( bool ) {
198
		row.removeClass( 'hidden' );
199
	}
200
	else {
201
		row.addClass( 'hidden' );
202
	}
203
};
204